﻿<!doctype html>
<html>
<!-- InstanceBegin template="/Templates/template1.dwt" codeOutsideHTMLIsLocked="false" -->
<head>
<meta charset="utf-8">
<!-- InstanceBeginEditable name="doctitle" -->
<title>预存变动详情</title>
<!-- InstanceEndEditable -->
<script type="text/javascript" src="../js/common.js"></script>
<script type="text/javascript" src="../js/utils.js"></script>
<script type="text/javascript" src="../js/checkLogin.js"></script>
<link href="../css/Pager.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="../js/jquery.pager.js"></script>
<link href="../css/style.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="../js/shopSelecterNew.js"></script>
<script type="text/javascript" src="../js/pagination.js"></script>
<script type="text/javascript" src="../js/dataTable.js"></script>
<script type="text/javascript" src="../js/doubleDate2.0.js"></script> 
<script type="text/javascript" src="../js/find.js"></script>
<script type="text/javascript" src="../js/qmsk-1.0.js"></script>
<!-- InstanceBeginEditable name="head" -->
<!-- InstanceEndEditable -->
<script type="text/javascript" >
/**
 * 入口，和服务器的通信从此开始
 */
 var gsonrst = "";
 
 var headNamedata = "";
 var oldNamedata = "";
 
$(function() {
	refreshInput($(".serWrapper"));
	initShopSelecter();
	
	$('.doubledate').kuiDate({
		className : 'doubledate',
		isDisabled : "0" // isDisabled为可选参数，“0”表示今日之前不可选，“1”标志今日之前可选
	});
	
	$('.doubledate1').kuiDate({
		className : 'doubledate1',
		isDisabled : "0" // isDisabled为可选参数，“0”表示今日之前不可选，“1”标志今日之前可选
	});
	initSelect();
	 $('#startDate').val(getToday());
	 $('#endDate').val(getToday());
});

function initSelect(){
	var shopId = $('#shopID').val();
	if(IsEmpty(shopId)){
		$("#shopIsChoosed").removeAttr("checked");
	}
	$('#mp').val("");
	$('#name').val("");
	$('#cardNo').val("");
}


/**
 * 为查找做准备，这里主要是生成查询条件对象
 */
function toSearch() {
	$("#sum").empty();
	$("#depositTotal").empty();
	var startDate = $('#startDate').val();
	var endDate = $('#endDate').val();
	if(IsEmpty(startDate)){
		art.dialog({fixed:true, lock: true,content:"起始日期为空",icon:'error',ok:true});	
		return false;
	}
	if(IsEmpty(endDate)){
		art.dialog({fixed:true, lock: true,content:"截止日期为空",icon:'error',ok:true});	
		return false;
	}
	
	/* if(getDateDiff(startDate,endDate) > 31){
		art.dialog({fixed:true, lock: true,content:"日期间隔不能超过31天",icon:'error',ok:true});	
		return false;
	} */
	
	var shopId = $('#shopID').val();
	var mp = $('#mp').val();
	var name = $('#name').val();
	var cardNo = $('#cardNo').val();
	var startDate = $('#startDate').val();
	var endDate = $('#endDate').val();
 	new Pagination({
		url : '../depositTotal/find/member/',
		data : {
			shopId : shopId,
			mp : mp,
			name : name,
			cardNo : cardNo,
			startDate : startDate,
			endDate : endDate
		},
		success : printDataToPage,
		pageSize : 10
	}); 
}

function printDataToPage(message){
	gsonrst = message;
	dataTable({
		tbodyId : 'depositTotal',
		heads : ["cardNo", "name","LevelName", "IDNumber", "mp",  "DepositAmount", "CustId"],
		rst : message,
		sup : {
			id : "sup",
			template : "共 [index] 条"
		},
		handler : [{
			col : 6,
			f : detail
		}]
	});
	findBalanceSum();
}

function downRescouse(){
	var startDate = $('#startDate').val();
	var endDate = $('#endDate').val();
	if(IsEmpty(startDate)){
		art.dialog({fixed:true, lock: true,content:"起始日期为空",icon:'error',ok:true});	
		return false;
	}
	if(IsEmpty(endDate)){
		art.dialog({fixed:true, lock: true,content:"截止日期为空",icon:'error',ok:true});	
		return false;
	}
	
	if(getDateDiff(startDate,endDate) > 31){
		art.dialog({fixed:true, lock: true,content:"日期间隔不能超过31天",icon:'error',ok:true});	
		return false;
	}
	
	var shopId = $('#shopID').val();
	var mp = $('#mp').val();
	var name = $('#name').val();
	var cardNo = $('#cardNo').val();
	var startDate = $('#startDate').val();
	var endDate = $('#endDate').val();
 	
	var param= {
			shopId : shopId,
			mp : mp,
			name : name,
			cardNo : cardNo,
			startDate : startDate,
			endDate : endDate
		}
	var params = $.param(param)
	window.location.href='../depositTotal/export/csv?'+params
	
}

function detail(heads,row){
	return "<input class='select common_btn' type='button' value='详情' onclick='toSelectCustInfo("+heads+","+row+")'>";
}

//拆分json头
function wcJsonhead(headName,rst, index,row){
	var isheadS = headName.indexOf('|');
	if(isheadS > 0){
		var tbadytd = headName.split('|');
		var dataValue = tbadytd[0];
		var rightValue = tbadytd[1];
		if(rightValue == "支出"){
			headNamedata = dataValue;
			if(headNamedata == oldNamedata ){
				$("#tr"+(index-1)).append("<td>"+getHtmlInt(getHeadIndexValue(row,rst,headName))+"</td>");
			}
		}else{
			oldNamedata = dataValue;
			$("#depositTotalInfo").append("<tr id='tr"+index+"'><td>"+dataValue+"</td><td>"+getHtmlInt(getHeadIndexValue(row,rst,headName))+"</td></tr>");

		}
	}
}


//初始化tbody
function tbadyInitCustInfo(rst, row){
	var heads = rst.result.head;

	for(var i =0;i<heads.length;i++){
		var head = heads[i];
		wcJsonhead(head,rst,i,row);
	}
	$("#custName").text(getHtmlString(getHeadIndexValue(row,rst,'name')));
	$("#sum1").html("合计预存:"+getHtmlInt(getHeadIndexValue(row,rst,'合计预存'))+"&nbsp&nbsp&nbsp 合计支出:"+getHtmlInt(getHeadIndexValue(row,rst,'合计支出')))
}

function toSelectCustInfo(heads, row){
	$("#depositTotalInfo").empty();
	$("#dpsitTotalInfo").show();
	$("#dpsitTotalSelect").hide();	
	if(IsEmpty(gsonrst)){
		return false;
	}
	tbadyInitCustInfo(gsonrst,row);
}

/**
 * 累计消费总和
 */
function findBalanceSum(){
	var shopId = $('#shopID').val();
	var mp = $('#mp').val();
	var name = $('#name').val();
	var cardNo = $('#cardNo').val();
	var startDate = $('#startDate').val();
	var endDate = $('#endDate').val();
	var rst = _findInfo("../depositTotal/find/member/sum",{
		"shopId" : shopId,
		"mp" : mp,
		"name" : name,
		"cardNo" : cardNo,
		"startDate" : startDate,
		"endDate" : endDate
	});
	
	if(IsNotEmpty(rst)){
			var htmlStr = "合计:"
			var htmlGD = "&nbsp&nbsp&nbsp";
			var sum = 0;
			var oldsum = 0;

			var depositAmount = getHtmlInt(getHeadIndexValue(0,rst,'DepositAmount'));
			if(depositAmount > 0){
				sum = sum+depositAmount;
				htmlStr += "预存总计:"+depositAmount;
				oldsum = sum;
			}
			

			var dpAmount = getHtmlInt(getHeadIndexValue(0,rst,'合计预存'));
			if(dpAmount > 0){
				sum = sum+dpAmount;
				if(oldsum < sum && oldsum != 0){
					htmlStr += htmlGD;
				}
				htmlStr += "合计总预存:"+dpAmount;
				oldsum = sum;
			}
			
			var rdpAmount = getHtmlInt(getHeadIndexValue(0,rst,'合计支出'));
			if(rdpAmount > 0){
				sum = sum+rdpAmount;
				if(oldsum < sum && oldsum != 0){
					htmlStr += htmlGD;
				}
				htmlStr += "合计总支出:"+rdpAmount;
				oldsum = sum;
			}
			
			
/* 			var integralAmount = getHtmlInt(getHeadIndexValue(0,rst,'IntegralAmount'));
			if(integralAmount > 0){
				sum = sum+integralAmount;
				if(oldsum < sum && oldsum != 0){
					htmlStr += htmlGD;
				}
				htmlStr += "积分总计:"+integralAmount;
				oldsum = sum;
			}
			
			var cashCouponAmount = getHtmlInt(getHeadIndexValue(0,rst,'CashCouponAmount'));
			if(cashCouponAmount > 0){
				sum = sum+cashCouponAmount;
				if(oldsum < sum && oldsum != 0){
					htmlStr += htmlGD;
				}
				htmlStr += "代金券总计:"+cashCouponAmount;
				oldsum = sum;
			} */
		if(sum > 0){
			$("#sum").html(htmlStr);
		}else{
			$("#sum").html("");
		}
	}
}


/**
 * 初始化店面选择器
 */
function initShopSelecter() {
	refreshInput($(".serWrapper"));
	$("#shopID").attr("disabled", "disabled");

	$("#shopIsChoosed").bind("click", function() {
		var checked = $(this).attr("checked");
		if (checked) {
			$("#shopID").removeAttr("disabled");
		} else {
			$("#shopID").attr("disabled", "disabled");
			$("#shopID").empty();
		}
	});
}

function toSelect() {
	$("#dpsitTotalInfo").hide();
	$("#dpsitTotalSelect").show();	
}

</script>
</head>

<body>
<div class="container" id="container">
  <div class="container_R fr" id ="dpsitTotalSelect">
    <div class="place">预存变动详情</div>
    <div class="member_search">
      <p><span>
        <input type="checkbox" id="shopIsChoosed" style="width:auto;height:auto;border:none;">
        店面：</span>
 		<select id="shopID"  class="shopName" onclick="openShopListPanel(this)" style="height: 20px;"></select>
 		 <span>起始日期：</span> <input type="text" readonly class="doubledate ipticon" id="startDate" /> 
 		 <span>截止日期：</span> <input type="text" readonly class="doubledate1 ipticon" id="endDate" />
      </p>
      <p>
       	<span>手机号：</span><input type="text" id="mp" class="absoluteTxt" >
      	<span>会员姓名：</span><input type="text" id="name" class="absoluteTxt" >
      	<span>会员卡号：</span>
      <input type="text" id="cardNo" class="absoluteTxt" >
      <input type="button" value="查询" class="btn" onclick="toSearch()">
      </p>
    </div>
    <table width="100%" class="member_list" cellpadding="0" cellspacing="1" border="0" id="memberList">
      <caption>
      <strong>预存变动会员信息列表 <span id="sup">共0条</span></strong> <a href="javascript:void(0)" onclick="downRescouse()">导出数据</a>
      </caption>
      <thead>
        <tr>
          <th>会员卡号</th>
          <th>会员姓名</th>
          <th>会员级别</th>
          <th>身份证号</th>
          <th>手机</th>
          <th>预存余额</th>
          <th>操作</th>
        </tr>
      </thead>
      <tbody id="depositTotal">
      
      </tbody>
    </table>
    
     <div id="NoResult"  class="Nothing" style="text-align:center;display: none;">无符合条件的数据！</div>
    <div id="sum" style="float: left;"></div>
    <div id="pager" class="pager"></div>
  </div>

  
  	<div class="container_R fr" style="padding: 17px; width: 773px;" id="dpsitTotalInfo">
		<div class="place"><a onclick="toSelect()">预存变动详情</a><span> &gt;</span> <span>会员预存变动详情</span><a class="goHome" onclick="toSelect()">返回</a></div>
	  	<table width="100%" class="member_list" cellpadding="0" cellspacing="1" border="0" id="memberList">
<!--       		<caption>
      			<strong>会员预存变动详情列表 <span id="sup1">共0条</span></strong> <a href="javascript:void(0)" onclick="downRescouse()">导出数据</a>
     		</caption> -->
     		 <strong>会员姓名:<span id="custName"></span></strong>
     		<thead>
		        <tr>
		          <th>付款日期</th>
		          <th>预存</th>
		          <th>支出</th>
<!-- 		          <th>身份证号</th>
		          <th>手机</th>
		          <th>预存余额</th>
		          <th>操作</th> -->
		        </tr>
      		</thead>
     	 	<tbody id="depositTotalInfo">
      
      		</tbody>
    	</table>
    	<div id="sum1" style="float: left;"></div>
	</div>
  <div class="fc"></div>
</div>



<!-- InstanceEndEditable --> 
<script type="text/javascript" src="../js/header.js"></script> 
<script type="text/javascript" src="../js/left.js"></script> 
<script type="text/javascript" src="../js/footer.js"></script> 
<script type="text/javascript">
clearThis("absoluteTxt");
</script>
</body>
<!-- InstanceEnd -->
</html>
